package com.cqc.jdk8.Jtime;

import org.junit.Test;

import java.time.*;
import java.time.format.DateTimeFormatter;

/**
 * @author cui
 * @date 2024/6/30 10:14
 * @description 时区相关API。暂时没用到，先不看了。
 * 详细见：https://blog.csdn.net/fox9916/article/details/134696467
 **/
public class ZoneTest {

    /**
     * 设置时区
     */
    @Test
    public void f1() {
        //now()=2023-03-06 20:00:08 中国比纽约快13个时区
        ZoneId zoneId = ZoneId.of("America/New_York");
        LocalDateTime now = LocalDateTime.now();
        ZonedDateTime zonedDateTime = ZonedDateTime.of(now, zoneId);
        //2023-03-06T20:00:18.379-05:00[America/New_York]
        System.out.println(zonedDateTime);

    }


    @Test
    public void f2() {
        LocalDateTime datetime = LocalDateTime.of(2024, Month.JUNE, 30, 0, 7);
        ZoneOffset offset = ZoneOffset.of("+05:30");
        OffsetDateTime date = OffsetDateTime.of(datetime, offset);
        System.out.println("Date and Time with timezone offset in Java : " + date);
        //todo ??
        String format = date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        System.out.println(format);
    }
}
